/*
#####################################################################
####################	   T R I B U I T 		#####################
#####################################################################

Copyright (C) 2010  Christoph Schnack, Berlin (Germany)

This file is part of Tribuit.

    Tribuit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Tribuit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Tribuit.  If not, see <http://www.gnu.org/licenses/>.


########################################################################
*/
package GuiTools;

import java.awt.*;

import javax.swing.*;

/**
 * 
 * Creates a customized JFrame. The JFrame is not resizable, is focusable and set with getTribuitIcon()
 * 
 * @author Christoph Schnack
 * @param title title of the JFrame
 */

public class TribuitFrame extends JFrame{
	public TMenuBar MENU;
	/**
	 * @author Christoph Schnack
	 * @param title title of the JFrame
	 */
	public TribuitFrame(String title){
		super(title);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setIconImage(GuiTools.getTribuitIcon());
		this.setResizable(false);
		this.setFocusable(true);
	}
	
	/**
	 * 
	 * Calls setSize(x,y) and setLocation(px,py) and setVisible(true) on the JFrame.
	 *  
	 * @author Christoph Schnack
	 * @param x x-size
	 * @param y y-size
	 * @param px x-location
	 * @param py y-location
	 */
	public void showUp(int x, int y, int px, int py){
		this.setSize(x,y);
		this.setLocation(px,py);
		this.setVisible(true);
	}
	
	/**
	 * Locates this at the top left Anchor of the argument JFrame, calls pack() and setVisible(true)
	 * 
	 * @author Christoph Schnack
	 * @param frame a JFrame
	 */
	public void showUpAt(JFrame frame){
		int x,y;
		if(frame.isVisible()&& frame.getState()==JFrame.NORMAL){
			Point pnt = frame.getLocationOnScreen();
			this.setLocation(pnt.x+frame.getWidth(),pnt.y);
		}
		else{
			Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
			if(screenSize.getHeight()<768){
				x=20;
				y=20;
			}
			else{
				x=100;
				y=100;
			}
			this.setLocation(x,y);
		}
		this.pack();
		this.setVisible(true);
	}
	
	/**
	 * Locates this at the top left Anchor of the argument JFrame, calls pack(), setVisible(true) and set PreferredSize(new Dimension(sizex, sizey).
	 * 
	 * @author Christoph Schnack 
	 * @param frame JFrame
	 * @param sizex x-size of the frame
	 * @param sizey y-size of the frame
	 */
	public void showUpAt(JFrame frame,int sizex,int sizey){
		if(frame.isVisible() && frame.getState()==JFrame.NORMAL){
			Point pnt = frame.getLocationOnScreen();
			this.setLocation(pnt.x+frame.getWidth(),pnt.y);
		}
		else this.setLocation(100,100);
		this.setPreferredSize(new Dimension(sizex,sizey));
		this.setSize(sizex,sizey);
		this.setVisible(true);
	}
	
	/** 
	 * Invokes pack(), setLocation(x,y) and setVisible(true) on the JFrame.
	 *  
	 * @author Christoph Schnack
	 * @param x x-location
	 * @param y y-location
	 */
	public void showUp(int x, int y){
		this.setLocation(x,y);
		this.pack();
		this.setVisible(true);
	}
	
	/**
	 * Invokes showUp(100,100).
	 * @see showUp(x,y);
	 */
	public void showUpAtTopLeftCorner(){
		showUp(100,100);
	}
	
	public void packAndKeepBounds(){
		this.setPreferredSize(this.getSize());
		pack();
	}
	
	/**
	 * Only to access EditVocDialog-Menu from OptionDialog.
	 * @author Christoph Schnack
	 */
	public void updateMenuBar(){
		if(MENU!=null)MENU.updateMenu();
	}

	/**
	 * 
	 * Adds a component to BorderLayout. Possible values are:"north", "center", "south", "east", "west"
	 * 
	 * @author Christoph Schnack
	 * @param position in BorderLayout
	 * @param component to add
	 */
	public void addPanel(String position,Component component){
		String option = "";
		if(position.equals("north")) option = BorderLayout.NORTH;
		if(position.equals("center")) option = BorderLayout.CENTER;
		if(position.equals("south")) option = BorderLayout.SOUTH;
		if(position.equals("east")) option = BorderLayout.EAST;
		if(position.equals("west")) option = BorderLayout.WEST;
		this.getContentPane().add(option, component);
	}
}